package ls.jpa.chapter5.service;

import ls.jpa.chapter5.entity.Person;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.util.List;

/**
 * @author Barudisshu
 */
@Service
public class PersonService {

    @PersistenceContext
    private EntityManager em;

    public Person findByName(String name){

        return em.find(Person.class,name);
    }

    public List<Person> findAll(){
        TypedQuery<Person> query = em.createQuery("select p from test p", Person.class);
        return query.getResultList();
    }

}
